<?php defined('SYSPATH') or die('No direct script access.');

class Model_ProductParser_Shop extends Model_ProductParser_Abstract
{ 
    public static function get_category_popular_products(Model_Shop $shop, $url)
    {
        $ids = array();
        
        if ($shop && method_exists(__CLASS__, '_parse_'.$shop->id)) {
            $ids = call_user_func(array(__CLASS__, '_parse_'.$shop->id), $url);
        }
        return $ids;
    }
    
    protected static function _parse_1001($url)
    {
        // 60 штук
        $ids = $tmp_ids = array();
        $source = Model_ProductParser_Abstract::_get_source_code($url);
        
        $source = Model_ProductParser_Abstract::_cut_str('<div class="content_box">', '</ul>', $source);
        while ($id = Model_ProductParser_Abstract::_cut_str('<li id="', '"', $source)) {
            $tmp_ids[] = $id;    
        }
        $n = count($tmp_ids);
        for ($i = 0; $i < $n; $i++) {
            $id   = $tmp_ids[$i];
            $sort = (int)(($n - $i-1)/($n/10)) + 1;
            $ids[] = array(
                'id'   => $id,
                'sort' => $sort,
            ); 
        }
        return $ids;
    }
    
    protected static function _parse_4102($url)
    {
        // 100 штук
        $ids = $tmp_ids = array();
        $source = Model_ProductParser_Abstract::_get_source_code($url);
        
        $source = Model_ProductParser_Abstract::_cut_str('<div class="catalog_main_table"', '<div id="catalog-overlay">', $source);
        while ($id = Model_ProductParser_Abstract::_cut_str("<div id='c", "'", $source)) {
            $tmp_ids[] = $id;    
        }
        $n = count($tmp_ids);
        for ($i = 0; $i < $n; $i++) {
            $id   = $tmp_ids[$i];
            $sort = (int)(($n - $i-1)/($n/10)) + 1;
            $ids[] = array(
                'id'   => $id,
                'sort' => $sort,
            );  
        }
        return $ids;
    }
}
